<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic"
	prefix="logic"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
	prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
	prefix="html"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="display-el"%>
<%@ taglib uri="ford-arg/tags" prefix="ft"%>

<script language="javascript">

	function findSupplier() {
		document.SupplierForm.action = "SupplierActionFind.do";
		document.SupplierForm.section.value = "find";
		document.SupplierForm.validateSubmit.value="find";
	}

	function editSupplier(obj) {
		document.SupplierForm.action = "SupplierActionEdit.do";
		document.SupplierForm.section.value = "edit";
		document.SupplierForm.numberSupplier.value=obj;
	}
	function newEconomicValue() {
		document.SupplierForm.action = "SupplierActionNewRegister.do";
	}
	
	function createUpdateSupplier() {
		document.SupplierForm.action = "SupplierActionCreateUpdate.do";
		document.SupplierForm.validateSubmit.value="validar";
	}
	
	function deleteSupplier(obj) {
		if (confirm('<bean:message key="supplier.confirmDelete" />')) {
			document.SupplierForm.action = "SupplierActionDelete.do";
			document.SupplierForm.numberSupplier.value=obj;
		}else{
			return false;
		}
	}
	

	
	function cancelSupplier(){
		document.SupplierForm.action = "SupplierActionClean.do";
		document.SupplierForm.validateSubmit.value="cancel";
		document.SupplierForm.section="false";
		
	}
	
	function selectDesc(){
	document.getElementById("codeFind").value = "";

	}
	function selectCode(){
	document.getElementById("descFind").value = "";

	}
	
	function selectOne(num){
		for(i=0; i<document.SupplierForm.elements.length; i++){
			var name = document.SupplierForm.elements[i].name.split('(');
			if(name[0]=='seleccMapped'){
				if(name[1].split(')')[0] != num)
				document.SupplierForm.elements[i].checked=false;
			}
		}
		document.SupplierForm.numberSupplier.value=num;
	}
	
	function goPartBySupplier(){
	if(document.SupplierForm.numberSupplier.value != ""){
		document.SupplierForm.action = "SupplierActionFindPart.do";
		document.SupplierForm.submit();
		}
	}
	function goPricingBySupplier(){
		if(document.SupplierForm.numberSupplier.value != ""){
		document.SupplierForm.action = "SupplierActionFindPricing.do";
		document.SupplierForm.submit();
		}
	}
</script>

<table>
	<tr>
		<td colspan="2">
		<h2><bean:message key="supplier.label.title" /></h2>
		</td>
	</tr>
</table>
<br />
<html:form action="/SupplierActionFind">
	<html:hidden property="section" />
	<html:hidden property="operation" />
	<html:hidden property="numberSupplier" />
	<html:hidden property="validateSubmit" />
	<%-- Mantiene el numero de pagina despues del submit --%>

	<bean:define id="codeSupplier">
		<bean:message key="supplier.label.codSupplier" />
	</bean:define>
	<bean:define id="nameSupplier">
		<bean:message key="supplier.label.name" />
	</bean:define>
	<bean:define id="classSupplier">
		<bean:message key="supplier.label.classsupplier" />
	</bean:define>

	<bean:define id="createSupplier">
		<bean:message key="label.created" />
	</bean:define>
	<bean:define id="updateSupplier">
		<bean:message key="label.updated" />
	</bean:define>
	<bean:define id="actionSupplier">
		<bean:message key="commodity.label.tableHeader.actions" />
	</bean:define>
	<bean:define id="actionTitle">
		<bean:message key="economicSource.label.tableHeader.actions" />
	</bean:define>
		<bean:define id="selectTitle">
		<bean:message key="label.select" />
	</bean:define>



	<%-- Panel de busqueda compartida --%>
	<table class="no_border" style="width:800px">
		<tr>
			<td colspan="100%">
			<table>
				<tr>
					<td class="text_blue_bold align_left" colspan="100%"><bean:message
						key="costStructure.item.label.filter" /></td>
				</tr>
				<tr>
				<td class="text_blue_bold align_left"><bean:message
						key="label.clase" /></td>
				<td class="align_left">
				<html:select property="supplierClassCode">
					<html:option value="-1"><bean:message key="label.allOption" /></html:option>
					<html:options collection="classCode"
								  property="value"
								  labelProperty="label" />
				</html:select>
				</td>
				</tr>
				<tr>
					<td class="text_blue_bold align_left"><bean:message
						key="economicIndexDef.label.code" /></td>
					<td class="align_left"><html:text property="codeFind"
						maxlength="8" onfocus="selectCode();" /></td>
				</tr>
				<tr>
					<td class="text_blue_bold align_left"><bean:message
						key="costStructure.item.label.name" /></td>
					<td class="align_left"><html:text property="descFind"
						maxlength="80" onfocus="selectDesc();" />&nbsp; &nbsp; <html:submit
						styleClass="button" onclick="findSupplier();">
						<bean:message key="label.find" />
					</html:submit></td>
				</tr>
			</table>
			</td>
		</tr>
		<tr>
			<td height="15px" />
		</tr>
		<!-- Fin de panel de busqueda -->
		<tr>
			
			<td>
			<div class="edit_out align_center" style="width:800px;">
			<div class="edit align_center" style="width: 800px;">
			<table style="width: 800px;" class="no_border">
				<tr>
					<!-- Titulos de Panel edicion creacion -->
					<td class="text_blue_bold align_left" width="181"><bean:message
						key="supplier.label.codSupplier" /></td>
					<td class="text_blue_bold align_left" width="181"><bean:message
						key="supplier.label.classsupplier" /></td>
					<td class="text_blue_bold align_left" width="181"><bean:message
						key="supplier.label.name" /></td>
				</tr>
				<tr>
					<!-- Dejara meter codigo de planta o no-->
					<logic:equal property="operation" value="edit" name="SupplierForm">
						<td class="text_blue_bold align_left" width="181"><bean:write name="SupplierForm"
							property="supplierSelected.eess01SupplierCodeC" /></td>
						<td  class="text_blue_bold align_left" width="181">
						<logic:equal
							property="supplierSelected.eess01SupplierClassCodeC" value="C"
							name="SupplierForm">
							<bean:message key="supplier.label.custom" />
						</logic:equal> 
						<logic:equal property="supplierSelected.eess01SupplierClassCodeC"
							value="F" name="SupplierForm">
							<bean:message key="supplier.label.ford" />
						</logic:equal></td>
						<td class="text_blue_bold align_left" width="181"><html:text name="SupplierForm"
							property="supplierSelected.eess01SupplierNameN" maxlength="80"/></td>
					</logic:equal>
					<logic:equal property="operation" value="create"
						name="SupplierForm">
						<td  class="text_blue_bold align_left" width="181"><html:text name="SupplierForm"
							property="supplierCodeN"  maxlength="6"/></td>
						<td class="text_blue_bold align_left" width="181"><html:select property="supplierClassN"
							onclick="isCustomSupplier()">
							<html:option value="-1" key="label.selectOption" />
							<html:option value="C" key="label.custom" />
						</html:select></td>
						<td  class="text_blue_bold align_left" width="181"><html:text name="SupplierForm"
							property="supplierNameN" /></td>
					</logic:equal>
					<td class="align_center"><html:submit
						styleClass="button_small" property=""
						onclick="createUpdateSupplier();">
						<bean:message key="label.createUpdate" />
					</html:submit> <html:submit styleClass="button_small" property=""
						onclick="cancelSupplier();">
						<bean:message key="label.new" />
					</html:submit></td>
			</table>
			</div>
			</div>
			</td>
		</tr>
		<tr>
			<td style="height: 15px" />
		</tr>
		<tr>
				<td class="align_left">
				<html:button property="supp" styleClass="button" style="width:120px;" onclick="goPartBySupplier()" ><bean:message key="part.label.title"/></html:button>
				<html:button property="yes" styleClass="button" style="width:60px;" onclick="goPricingBySupplier()" ><bean:message key="part.label.pricing"/></html:button></td>
				
		</tr>
		<tr>
			<td><ft:saveActivePageNumber /><display-el:table class="table1"
				style="width: 800px;" cellpadding="5" uid="supplier" pagesize="12"
				name="sessionScope.SupplierForm.suppliers" excludedParams="*"
				requestURI="SupplierActionPaginate.do">
				<display-el:column title="${codeSupplier}"
					property="eess01SupplierCodeC" style="width: 25%;"
					class="cell1 text_bold border1_right border1_top align_left"
					headerClass="header border_right" />
				<display-el:column title="${nameSupplier}"
					property="eess01SupplierNameN" style="width: 25%;"
					class="cell1 text_bold border1_right border1_top align_left"
					headerClass="header border_right" />
				<display-el:column title="${classSupplier}" style="width: 25%;"
					class="cell1 text_bold border1_right border1_top align_left"
					headerClass="header border_right">
					<logic:equal property="eess01SupplierClassCodeC" value="C"
						name="supplier">
						<bean:message key="supplier.label.custom" />
					</logic:equal>
					<logic:equal property="eess01SupplierClassCodeC" value="F"
						name="supplier">
						<bean:message key="supplier.label.ford" />
					</logic:equal>
				</display-el:column>
				<display-el:column title="${createSupplier}" style="width: 25%;"
					decorator="ar.com.ford.it.fullEconomics.view.displaytag.CostStructureItemColumnDecorator"
					class="cell1 text_bold border1_right border1_top align_left"
					headerClass="header border_right">
							${supplier.eess01CreateUserC}<br />${supplier.eess01CreateS}
					</display-el:column>
				<display-el:column title="${updateSupplier}" style="width: 25%;"
					decorator="ar.com.ford.it.fullEconomics.view.displaytag.CostStructureItemColumnDecorator"
					class="cell1 text_bold border1_right border1_top align_left"
					headerClass="header border_right">
							${supplier.eess01LastUpdtUserC}<br />${supplier.eess01LastUpdtS}
					</display-el:column>
				<display-el:column title="${actionTitle}" style="width: 25%;"
					class="cell1 text_bold border1_right border1_top align_left"
					headerClass="header border_right">
				<logic:equal property="eess01SupplierClassCodeC" value="F" name="supplier">
					<html:image property="" onclick="editSupplier(${supplier_rowNum});"
						page="/images/edit.gif" style="width:20px" alt="Editar" disabled="true"/>&nbsp;
							<html:image property=""
						onclick="deleteSupplier(${supplier_rowNum});"
						page="/images/erase.gif" style="width:20px" alt="Eliminar" disabled="true"/>&nbsp;
					</logic:equal>
				<logic:equal property="eess01SupplierClassCodeC" value="C" name="supplier">
					<html:image property="" onclick="editSupplier(${supplier_rowNum});"
						page="/images/edit.gif" style="width:20px" alt="Editar" />&nbsp;
							<html:image property=""
						onclick="deleteSupplier(${supplier_rowNum});"
						page="/images/erase.gif" style="width:20px" alt="Eliminar" />&nbsp;
					</logic:equal>

				</display-el:column>
				<display-el:column title="${selectTitle}"  style="width: 10%;" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right">
						<html:checkbox property="seleccMapped(${supplier_rowNum})" onclick="selectOne(${supplier_rowNum});"></html:checkbox>
				</display-el:column>
				
			</display-el:table></td>
		</tr>
	</table>
</html:form>
